/**
 * <p>Title: ServiceZM92.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2012-11-12 上午05:12:40  张志芳  Create
 *</pre>
 */
package com.baosight.sczx.zm.service;

import java.util.Map;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.common.zm.cInterface.IndexConfiger;
import com.baosight.sczx.common.zm.cInterface.cp.ProduceStatistics;
import com.baosight.sczx.zm.domain.ZM92;

/**
 * 首页——生产统计
 * <p>Title: ServiceZM92.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2012-11-12 上午05:12:40  张志芳  Create
 *</pre>
 */
public class ServiceZM92 extends ServiceEPBase {

	/**
	 * 初始化
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZM92</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-11-26上午01:09:05 张志芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的		
		return query(inInfo);		
	}
	
	/**
	 * 查询
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZM92</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-11-26上午01:09:13 张志芳
	 * </p>
	 *
	 */
	public EiInfo query(EiInfo inInfo) {
		String date = StaticTools.getDate();
		String[] my = ProduceStatistics.getStatisticsYearMonth(date);
		String monthStartDate = ProduceStatistics.getStatisticsBeginDate(my[0],my[1]);
		String monthStopDate = ProduceStatistics.getStatisticsEndDate(my[0],my[1]);
		String yearStartDate = ProduceStatistics.getStatisticsBeginDate(my[0],"1");
		String yearStopDate = ProduceStatistics.getStatisticsEndDate(my[0],"12");
		
		StaticTools.setQueryParameters(inInfo, "fdYear", my[0], true);//添加查询条件
		StaticTools.setQueryParameters(inInfo, "fdMonth", my[1], true);//添加查询条件
		StaticTools.setQueryParameters(inInfo, "fdYearBeginDate", yearStartDate, true);//添加查询条件
		StaticTools.setQueryParameters(inInfo, "fdYearEndDate", yearStopDate, true);//添加查询条件
		StaticTools.setQueryParameters(inInfo, "fdBeginDate", monthStartDate, true);//添加查询条件
		StaticTools.setQueryParameters(inInfo, "fdEndDate", monthStopDate, true);//添加查询条件
		StaticTools.setQueryParameters(inInfo, "fdDate", StaticTools.getDate(-1, date, "yyyy-MM-dd"), true);//添加查询条件
		
		EiInfo outInfo=new EiInfo();
		
		if("否".equals(IndexConfiger.getInstance().getIsLeader()))
		{
			String department = UserSession.getInSessionProperty("orgCode")==null?"":UserSession.getInSessionProperty("orgCode").toString();
			StaticTools.setQueryParameters(inInfo, "fdDepartemnt", department, true);
			Map map = Department.getInstance().getDepartmentMapById(department);
			if("采煤".equals(map.get("ext2")))
			{
				outInfo.addBlock(super.query(inInfo,"ZM92.queryMine", new ZM92(), false, null, EiConstant.queryBlock, EiConstant.resultBlock, "resultMine").getBlock("resultMine"));
				return outInfo;
			}
			else if("掘进".equals(map.get("ext2")))
			{
				outInfo.addBlock(super.query(inInfo,"ZM92.queryGrub", new ZM92(), false, null, EiConstant.queryBlock, EiConstant.resultBlock, "resultGrub").getBlock("resultGrub"));
				return outInfo;
			}
		}
		
		outInfo.addBlock(super.query(inInfo,"ZM92.queryMine", new ZM92(), false, null, EiConstant.queryBlock, EiConstant.resultBlock, "resultMine").getBlock("resultMine"));
		outInfo.addBlock(super.query(inInfo,"ZM92.queryGrub", new ZM92(), false, null, EiConstant.queryBlock, EiConstant.resultBlock, "resultGrub").getBlock("resultGrub"));
		return outInfo;
	}
}
